<h3>Les contenus</h3>

<fieldset>
<legend>Ajouter un contenu</legend>
<select id="structureAdd">
		<?php 
			echo '<option value="-1">Selectionner la structure</option>';
		foreach($this->assign['dataStruct'] as $key => $val){
			echo'<option value="'.$val['contentobject_structure_id'].'">'.$val['contentobject_structure_caption'].'</option>';
		}
		?>
</select>
	
</fieldset>


<fieldset>
<legend>Lister les contenus</legend>
<div>
	<?php 
		echo '<select id="structureEdit" name="contentobject[collection_id]">';
		echo '<option value="-1">Selectionner une url</option>';
		foreach($this->assign['directory']['page'] as $key => $val){
			if(isset($val['controller'])){
				echo'<option value="'.$val['id_collection'].'">'.$key.'</option>';
			}else{
				foreach($val as $key2 => $val2){
						echo'<option value="'.$val2['id_collection'].'">'.$key.' > '.$key2.'</option>';
				}
			}
		}
		echo '</select>';
	?>
</div>

<?php 
	if(isset($this->args['path'][3]) && !empty($this->args['path'][3]) && $this->assign['dataContent']<>0){
		echo'<table>';
			echo'<thead>';
				echo'<th>';
					echo'<td>contentobject_date_create</td>';
					echo'<td>contentobject_id</td>';
					echo'<td>contentobject_value_text</td>';
					echo'<td>action</td>';
				echo'<th>';
			echo'<thead>';

			echo'<tbody>';
			foreach($this->assign['dataContent'] as $key => $val){
				echo'<th>';
					echo'<td>'.$val['contentobject_date_create'].'</td>';
					echo'<td>'.$val['contentobject_id'].'</td>';
					echo'<td>'.$val['elems'][0]['contentobject_value_text'].'</td>';
					echo'<td><input class="btn-structureEdit" rel="'.$val['contentobject_id'].'" type="button" value="Editer" /></td>';
				echo'<th>';
			}
			echo'<tbody>';
		echo'</table>';
	}elseif(isset($this->args['path'][3]) && !empty($this->args['path'][3]) && $this->assign['dataContent']==0){
		echo'<div>Aucun contenu dans cette url</div>';
	}

?>
</fieldset>

<script>
	$('#structureEdit').change(function(){
		var structure_id = $(this).attr("value");
		if(structure_id>0){
			document.location.href = '/admin/contenu/'+structure_id;
		}
	});

	$('.btn-structureEdit').live('click',function(){
		var content_id = $(this).attr("rel");
			document.location.href = '/admin/contenu/editer/'+content_id;
	});


	$('#structureAdd').change(function(){
		var structure_id = $(this).attr("value");
		if(structure_id>0){
			document.location.href = '/admin/contenu/creer/'+structure_id;
		}
	});
</script>